package com.mjh.partners.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.mjh.partners.mapper.ExperienceMapper;
import com.mjh.partners.mapper.PraiseMapper;
import com.mjh.partners.pojo.Praise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;



@RequestMapping("/PraiseController")
@Controller
public class PraiseController {
  @Autowired
  private PraiseMapper praiseMapper;
  @Autowired
  private ExperienceMapper experienceMapper;
  @ResponseBody
  @RequestMapping("addPraise")
  public String addPraise(int eid,int userid) {
    String nowTime=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
    Praise praise = new Praise();
    praise.setpChangeTime(nowTime);
    praise.setEid(eid);
    praise.setUserid(userid);
    boolean flag1=praiseMapper.addPraise(praise);
    boolean flag2=experienceMapper.addPraiseOnEx(eid);
    if(flag1&&flag2) {
      return "success";
    }else {
      return "error";
    }
  }
  
  @ResponseBody
  @RequestMapping("deletePraise")
  public String deletePraise(int eid,int userid) {
    boolean flag1=praiseMapper.deletePraise(eid, userid);
    boolean flag2=experienceMapper.deletePraiseOnEx(eid);
    if(flag1&&flag2) {
      return "success";
    }else {
      return "error";
    }
  }
}
